package com.clkj.cldisabledmanclient.http;

import com.google.gson.JsonObject;

import java.util.concurrent.TimeUnit;

import io.reactivex.Observable;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.RequestBody;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.Multipart;
import retrofit2.http.POST;
import retrofit2.http.Part;

/**
 * Created by clboys on 2019/5/14.
 */

public interface HttpService {


    /**
     * 登录接口
     *
     * @param userName
     * @param passWord
     * @param roleId
     * @return
     */
    @FormUrlEncoded
    @POST("/CDPFIN/login")
    Observable<JsonObject> login(@Field("username") String userName, @Field("password") String passWord,
                                 @Field("roleId") String roleId);

    //获取服务流程说明
    @FormUrlEncoded
    @POST("/CDPFIN/getProcessingProcess")
    Observable<JsonObject> getServiceIntrosuction(@Field("type") String type);

    //获取我的个人信息
    @FormUrlEncoded
    @POST("/CDPFIN/getPersonInfo")
    Observable<JsonObject> getMyPersonInfo(@Field("IdCard") String IdCard);

    //获取我的康复机构列表
    @FormUrlEncoded
    @POST("/CDPFIN/getInstitutionList")
    Observable<JsonObject> getMyRecoverOrgList(@Field("IdCard") String IdCard, @Field("page") String page,
                                               @Field("rows") String rows);

    //获取所有康复机构列表
    @FormUrlEncoded
    @POST("/CDPFIN/getAllInstitutionList")
    Observable<JsonObject> getAllRecoverOrgList(@Field("page") String page, @Field("rows") String rows);

    //获取我的康复机构详情
    @FormUrlEncoded
    @POST("/CDPFIN/getInstitutionDetail")
    Observable<JsonObject> getMyRecoverOrgDetail(@Field("institutionId") String institutionId);

    //获取康复机构康复师列表
    @FormUrlEncoded
    @POST("/CDPFIN/getTeacherList")
    Observable<JsonObject> getTeacherList(@Field("institutionId") String institutionId, @Field("page") String page,
                                          @Field("rows") String rows);

    //提交机构满意度分数
    @FormUrlEncoded
    @POST("/CDPFIN/submitInstitutionScore")
    Observable<JsonObject> submitInstitutionScore(@Field("institutionId") String institutionId, @Field("personnelId") String personnelId,
                                                  @Field("institutionScore") String institutionScore);

    //获取我的康复训练计划列表
    @FormUrlEncoded
    @POST("/CDPFIN/getPlanList")
    Observable<JsonObject> getPlanList(@Field("IdCard") String IdCard, @Field("page") String page,
                                       @Field("rows") String rows);


    //获取我的康复训练计划详情
    @FormUrlEncoded
    @POST("/CDPFIN/getPlanDetail")
    Observable<JsonObject> getPlanDetail(@Field("planId") String planId);

    //获取我的康复训练记录列表
    @FormUrlEncoded
    @POST("/CDPFIN/getProgressList")
    Observable<JsonObject> getProgressList(@Field("IdCard") String IdCard, @Field("page") String page,
                                           @Field("rows") String rows);

    //获取我的康复训练记录详情
    @FormUrlEncoded
    @POST("/CDPFIN/getProgressDetail")
    Observable<JsonObject> getProgressDetail(@Field("progressId") String progressId);


    //获取家庭康复训练记录详情
    @FormUrlEncoded
    @POST("/CDPFIN/getAttendanceHomeDetail")
    Observable<JsonObject> getHomeTrainDetail(@Field("IdCard") String IdCard, @Field("date") String date);

    //获取家庭康复训练记录列表
    @FormUrlEncoded
    @POST("/CDPFIN/getAttendanceHomeList")
    Observable<JsonObject> getHomeTrain(@Field("IdCard") String IdCard, @Field("page") String page,
                                        @Field("rows") String rows);

    //判断当天是否点击居家康复按钮getJudge
    @FormUrlEncoded
    @POST("/CDPFIN/getJudge")
    Observable<JsonObject> getJudge(@Field("IdCard") String IdCard, @Field("state") String state,
                                    @Field("today") String today);

    //获取我的评估列表
    @FormUrlEncoded
    @POST("/CDPFIN/getAssessmentList")
    Observable<JsonObject> getAssessmentList(@Field("IdCard") String IdCard, @Field("page") String page,
                                             @Field("rows") String rows);

    //获取满意度调查问卷列表
    @FormUrlEncoded
    @POST("/CDPFIN/getQuestionnaireList")
    Observable<JsonObject> getQuestionnaireList(@Field("username") String username, @Field("page") String page,
                                                @Field("rows") String rows);

    //获取满意度调查问卷详情
    @FormUrlEncoded
    @POST("/CDPFIN/getQuestionnaireByQId")
    Observable<JsonObject> getQuestionnaireByQId(@Field("qId") String qId, @Field("realname") String realname);

    //获取我的评估详情
    @FormUrlEncoded
    @POST("/CDPFIN/getAssessmentDetail")
    Observable<JsonObject> getAssessmentDetail(@Field("assessmentId") String assessmentId);

    //获取区县数据列表
    @POST("/CDPFIN/getRegionalism")
    Observable<JsonObject> getRegionalism();

    //获取残疾类别数据列表
    @POST("/CDPFIN/getDisabilityCategory")
    Observable<JsonObject> getDisabilityCategory();

    //获取家庭类别数据列表
    @POST("/CDPFIN/getFamilyCategory")
    Observable<JsonObject> getFamilyCategory();


    //获取经济来源数据列表
    @POST("/CDPFIN/getEconomicSource")
    Observable<JsonObject> getEconomicSource();

    //获取可选择的康复机构列表接(根据残疾类型)
    @FormUrlEncoded
    @POST("/CDPFIN/getInstitutionByDisabilityCategory")
    Observable<JsonObject> getInstitutionByDisabilityCategory(@Field("disabilityCategory") String disabilityCategory);


    //获取我的申请列表
    @FormUrlEncoded
    @POST("/CDPFIN/getPersonnelList")
    Observable<JsonObject> getPersonnelList(@Field("IdCard") String IdCard, @Field("page") String page,
                                            @Field("rows") String rows);


    //获取我的申请详情
    @FormUrlEncoded
    @POST("/CDPFIN/getPersonnelDetail")
    Observable<JsonObject> getPersonnelDetail(@Field("personnelId") String personnelId);

    //获取活动列表
    @FormUrlEncoded
    @POST("/CDPFIN/getActiveList")
    Observable<JsonObject> getActiveList( @Field("page") String page,
                                            @Field("rows") String rows);

    //获取活动詳情
    @FormUrlEncoded
    @POST("/CDPFIN/getActiveDetail")
    Observable<JsonObject> getActiveDetail( @Field("informationId") String informationId);

    //提交申请
    @Multipart
    @POST("/CDPFIN/submitTrainingApplication")
    Observable<JsonObject> submitApply(@Part("area") RequestBody area, @Part("country") RequestBody country, @Part("name") RequestBody name,
                                       @Part("gender") RequestBody gender, @Part("birthday") RequestBody birthday, @Part("disabilityCategory") RequestBody disabilityCategory,
                                       @Part("IdCard") RequestBody IdCard, @Part("address") RequestBody address, @Part("guardianName") RequestBody guardianName,
                                       @Part("guardianRelationship") RequestBody guardianRelationship, @Part("guardianCompany") RequestBody guardianCompany,
                                       @Part("guardianTel") RequestBody guardianTel, @Part("guardianName2") RequestBody guardianName2,
                                       @Part("guardianRelationship2") RequestBody guardianRelationship2, @Part("guardianCompany2") RequestBody guardianCompany2,
                                       @Part("guardianTel2") RequestBody guardianTel2, @Part("familyCategory") RequestBody familyCategory,
                                       @Part("economicSource") RequestBody economicSource, @Part("personnelAnnualIncome") RequestBody personnelAnnualIncome,
                                       @Part("institutionId") RequestBody institutionId, @Part("reasonDemand") RequestBody reasonDemand,
                                       @Part MultipartBody.Part personnelImgage, @Part MultipartBody.Part guardianIDCard,
                                       @Part MultipartBody.Part guardianResidenceBooklet, @Part MultipartBody.Part childrenResidenceBooklet,
                                       @Part MultipartBody.Part lowAssurance, @Part MultipartBody.Part disabilityCertificate,
                                       @Part MultipartBody.Part hospitalProve);

    //提交申请
    @Multipart
    @POST("/CDPFIN/submitTrainingApplication")
    Observable<JsonObject> submitApply2(@Part("area") RequestBody area, @Part("country") RequestBody country, @Part("name") RequestBody name,
                                        @Part("gender") RequestBody gender, @Part("birthday") RequestBody birthday, @Part("disabilityCategory") RequestBody disabilityCategory,
                                        @Part("IdCard") RequestBody IdCard, @Part("address") RequestBody address, @Part("guardianName") RequestBody guardianName,
                                        @Part("guardianRelationship") RequestBody guardianRelationship, @Part("guardianCompany") RequestBody guardianCompany,
                                        @Part("guardianTel") RequestBody guardianTel, @Part("guardianName2") RequestBody guardianName2,
                                        @Part("guardianRelationship2") RequestBody guardianRelationship2, @Part("guardianCompany2") RequestBody guardianCompany2,
                                        @Part("guardianTel2") RequestBody guardianTel2, @Part("familyCategory") RequestBody familyCategory,
                                        @Part("economicSource") RequestBody economicSource, @Part("personnelAnnualIncome") RequestBody personnelAnnualIncome,
                                        @Part("institutionId") RequestBody institutionId, @Part("reasonDemand") RequestBody reasonDemand,
                                        @Part MultipartBody.Part personnelImgage, @Part MultipartBody.Part guardianIDCard,
                                        @Part MultipartBody.Part guardianResidenceBooklet, @Part MultipartBody.Part childrenResidenceBooklet,
                                        @Part MultipartBody.Part lowAssurance, @Part MultipartBody.Part hospitalProve);

    class Factory {

        private static OkHttpClient generateOkHttpClient() {
            OkHttpClient httpClient = new OkHttpClient.Builder()
                    /*
            这里可以添加一个HttpLoggingInterceptor，因为Retrofit封装好了从Http请求到解析，
            出了bug很难找出来问题，添加HttpLoggingInterceptor拦截器方便调试接口
             */
                    .addInterceptor(new LoggingInterceptor())
                    .readTimeout(2, TimeUnit.MINUTES)
                    .connectTimeout(2, TimeUnit.MINUTES)
                    .writeTimeout(2, TimeUnit.MINUTES)
                    .build();


            return httpClient;
        }

        public static HttpService create(String baseUrl) {


            Retrofit retrofit = new Retrofit.Builder()
                    .baseUrl(baseUrl + "/")
                    .client(generateOkHttpClient())
                    .addConverterFactory(GsonConverterFactory.create())
                    .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                    .build();
            return retrofit.create(HttpService.class);
        }
    }
}

